package com.group4.banner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group4.banner.entity.Banner;
import com.group4.banner.mapper.BannerMapper;
import com.group4.banner.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public void addBanner(Banner banner) {
        bannerMapper.insert(banner);
    }

    @Override
    public List<Banner> getAll() {
        QueryWrapper<Banner> queryWrapper=new QueryWrapper<>();
        return bannerMapper.selectList(queryWrapper);
    }

    @Override
    public Banner fingById(String id) {
        return bannerMapper.selectById(id);
    }

    @Override
    public void deleteById(String id) {
        bannerMapper.deleteById(id);
    }

    /**
     * 实现分页查询
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<Banner> pageinfo(int pageNum) {
        //pageNem页码表示从哪里开始
        PageHelper.startPage(pageNum,2);
         List<Banner> page = bannerMapper.page();
        return new PageInfo<>(page);
    }
}
